from datetime import datetime
from typing import Optional
from fastapi import Query
from pydantic import BaseModel, Field

from forward.utils.tools import ToolsUtil


class SystemLogSmsSchema(BaseModel):
    id: int = Field(..., description="主键", ge=0)
    scene: int = Field(..., description="场景编号", ge=0)
    mobile: str = Field(..., description="手机号码", min_length=1, max_length=32)
    content: str = Field(..., description="发送内容", min_length=1, max_length=255)
    status: int = Field(
        ..., description="发送状态：[0=发送中, 1=发送成功, 2=发送失败]", ge=0, le=2
    )
    results: Optional[str] = Field(None, description="短信结果")
    send_time: int = Field(..., description="发送时间", ge=0)
    created_time: datetime|None = Field(None, description="创建时间")
    updated_time: datetime|None = Field(None, description="更新时间")
    
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class SmsSendInSchema(BaseModel):
    """
    短信发送 入参
    """

    scene: int  # 场景  [101=登录验证码, 102=绑定手机验证码, 103=变更手机验证码, 104=找回登录密码验证码]
    mobile: str = Query(
        max_length=11, min_length=11, regex="^[1][3,4,5,6,7,8,9][0-9]{9}$"
    )
